<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<style>


</style>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">专家互评</h4>
</div>
<div class="modal-body">


    <form id="form_data">
        <div class="table-responsive">
            <table class="table table-hover table-striped table-bordered">
                <tr>
                    <th>姓名</th>
                    <th>身份证号</th>
                    <th>类型</th>
                    <th>专家类型</th>
                    <th>证书编号</th>
                    <th style="width: 80px">协调配合能力</th>
                    <th style="width: 80px">专家业务能力</th>
                    <th style="width: 80px">公平公正性</th>
                    <th style="width: 80px">廉洁自律</th>
                    <th style="width: 80px">综合评价</th>
                </tr>

                <input type="hidden" name="businessId" value="${businessId}">
                <input type="hidden" name="fromInspectorId" value="${fromInspectorId}">

                <c:forEach items="${data}" varStatus="status" var="i">
                    <tr>
                        <td>${i.expertName}</td>
                        <td>${i.expertIdCard}</td>
                        <td>
                        <c:choose>
                            <c:when test="${i.expertRole=='leader'}">组长</c:when>
                            <c:otherwise>组员</c:otherwise>
                        </c:choose>
                        </td>
                        <td>${i.certificateGrade}</td>
                        <td>${i.certificateNum}</td>
                        <input type="hidden" name="inspectorAssessList[${status.index}].toInspectorId" value="${i.id}">

                        <td>
                            <select class="form-control" onchange="reSetInput(${status.index});" name="inspectorAssessList[${status.index}].cooperation">
                                <option value="2">好</option>
                                <option value="1">一般</option>
                                <option value="0">差</option>
                            </select>
                        </td>
                        <td>
                            <select class="form-control" onchange="reSetInput(${status.index});" name="inspectorAssessList[${status.index}].business">
                                <option value="2">好</option>
                                <option value="1">一般</option>
                                <option value="0">差</option>
                            </select>
                        </td>
                        <td>
                            <select class="form-control" onchange="reSetInput(${status.index});" name="inspectorAssessList[${status.index}].fairness">
                                <option value="2">好</option>
                                <option value="1">一般</option>
                                <option value="0">差</option>
                            </select>
                        </td>
                        <td>
                            <select class="form-control" onchange="reSetInput(${status.index});" name="inspectorAssessList[${status.index}].honest">
                                <option value="2">好</option>
                                <option value="1">一般</option>
                                <option value="0">差</option>
                            </select>
                        </td>
                        <td>
                            <select class="form-control" disabled  name="inspectorAssessList[${status.index}].comprehensive">
                                <option value="2">好</option>
                                <option value="1">一般</option>
                                <option value="0">差</option>
                            </select>
                        </td>
                    </tr>
                </c:forEach>
                <tr>
                    <td colspan="10" style="text-align: left">
                        “综合评价”的判定原则为：<br>
                        　　有1项以上(含1项)为“差”的，综合评价为“差”；<br>
                        　　有2项以上(含2项)为“一般”的，综合评价为“一般”；<br>
                        　　其他情况综合评价为“好”。<br>
                    </td>
                </tr>
                <tr>
                    <td colspan="10" style="text-align: center">
                        <button type="submit"
                                class="btn btn-default btn-success"><span
                                class="glyphicon glyphicon-ok"></span>&nbsp;确&nbsp;定&nbsp;
                        </button>
                    </td>
                </tr>
            </table>
        </div>
    </form>

</div>

<script>


    function reSetInput(index) {

        var cooperation = $('select[name="inspectorAssessList[' + index + '].cooperation"]').val();
        var business = $('select[name="inspectorAssessList[' + index + '].business"]').val();
        var fairness = $('select[name="inspectorAssessList[' + index + '].fairness"]').val();
        var honest = $('select[name="inspectorAssessList[' + index + '].honest"]').val();
        var result = cooperation * business * fairness * honest;
        var comprehensive =$('select[name="inspectorAssessList[' + index + '].comprehensive"]');
        console.log(result);
        if (result == 0) {
            comprehensive.val('0');
        } else if (result <= 4) {
            comprehensive.val('1');
        } else {
            comprehensive.val('2');
        }

        comprehensive.trigger('change.select2');
    }






    <%--bootstrapValidator--%>
    var $form_data = $("#form_data");
    $form_data.bootstrapValidator({}).on('success.form.bv', function (e) {
        e.preventDefault();

        $.sysPlugin.superAjax({
            data: $form_data.serializeObject(),
            url: '${url}',
            operateType: '${operateType}',
            showSuccessAlert: true,
            showWarnAlert: true,
            successCall: function (data) {
                $.sysPlugin.successCallBack(data, {
                    modal: $("#modal_ajax"),
                    table: $("#table_data")
                })
            },
            errorCall: function (data) {
                $.sysPlugin.errorCallBack(data, {
                    form: $form_data
                })
            }, warnAlertCancelCall: function () {
                $form_data.data('bootstrapValidator').resetForm();
            }

        })
    });


    $.sysPlugin.initSimpleSelect2();
</script>
